package org.example.network;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Demo2Server {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8888);
        System.out.println("服务器启动了, 监听端口: 8888");
        Socket socket = serverSocket.accept();
        System.out.println("客户端连接了");
        System.out.println("socket.getInetAddress() = " + socket.getInetAddress());
        System.out.println("socket.getLocalAddress() = " + socket.getLocalAddress());

        Demo2Talker demo2Talker = new Demo2Talker(socket, "客户端");
        new Thread(demo2Talker::send).start();
        new Thread(demo2Talker::recv).start();
    }

}
